package csc.daonjpa.java.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;

import share.Constant;
import csc.daonjpa.java.domain.Admin;

@Repository
public class AdminDAO {

	@PersistenceContext
	EntityManager entityManager;
	
	public Admin checkLogin(String loginId, String password) {
		
		Admin admin = null;
		
		String md5Pass = Constant.getMD5Code(password);
		
		try{
			TypedQuery<Admin> query = entityManager
					.createQuery(
							"SELECT a FROM " 
					+ Admin.class.getName()
					+ " a WHERE a.loginId= :loginId and a.password= :password",
					Admin.class);
			query.setParameter("loginId", loginId);
			query.setParameter("password", md5Pass);
			
			admin = query.getSingleResult();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return admin;
	}

}
